package com.rightsidetech.http.controller.admin.system;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.DelReq;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.FeedbackPageReq;
import com.rightsidetech.system.dtos.request.FeedbackTempSaveReq;
import com.rightsidetech.system.dtos.request.ReplyReq;
import com.rightsidetech.system.dtos.request.UpdateFeedBackStatusReq;
import com.rightsidetech.system.dtos.response.FeedbackPageResp;
import com.rightsidetech.system.dtos.response.SysFeedbackTempResp;
import com.rightsidetech.system.service.SysFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import java.util.List;

/**
 * @Author: yhr
 * @Date: 2021-12-15 15:21
 */
@RestController
@RequestMapping("/admin/feedback")
@ShenyuSpringMvcClient(path = "/admin/feedback/**")
@Api(tags = "admin:用户反馈相关")
public class SysFeedbackController extends BaseController {
    @Resource
    private SysFeedbackService sysFeedbackService;

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/tempPage")
    @ApiOperation("反馈问题模板列表")
    public ResponseData<List<SysFeedbackTempResp>> tempPage() throws Exception {
        return sysFeedbackService.selectAllTemp();
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/saveTemp")
    @ApiOperation("添加反馈问题")
    public ResponseData saveTemp(@RequestBody FeedbackTempSaveReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysFeedbackService.saveTemp(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/delTemp")
    @ApiOperation("删除反馈问题")
    public ResponseData delTemp(@RequestBody DelReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysFeedbackService.delTemp(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page")
    @ApiOperation("用户反馈列表")
    public ResponseData<PageInfo<FeedbackPageResp>> page(FeedbackPageReq req) throws Exception {
        return sysFeedbackService.page(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/updateStatus")
    @ApiOperation("已读")
    public ResponseData updateStatus(@RequestBody UpdateFeedBackStatusReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysFeedbackService.updateStatus(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/reply")
    @ApiOperation("回复")
    public ResponseData reply(@RequestBody ReplyReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysFeedbackService.reply(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/search")
    @ApiOperation("反馈问题下拉")
    public ResponseData search() throws Exception {
        return sysFeedbackService.search();
    }
}
